<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="css/mui.min.css">
		<style>
			html,body {
				background-color: #efeff4;
			}
			.mui-scroll{
				/*margin: 10px 0px 10px;*/
				/*color: #6d6d72;*/
				font-size: 15px;
			}
			.mui-table-view{
				border: none;
			}
			.mui-table-view-cell{
				margin: 10px 0 10px;
				border: none;
				height: auto;
				width: auto;
				overflow: hidden;
				padding: 0 0;
			}
			a img{
				margin: 0 0;
				width: 100%;
				height: auto;
			}
			.mui-table-view-cell .hover{
				background-color: #FFFFFF;
			}
		</style>
	</head>

	<body>
		<div class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<ul id="listParent" class="mui-table-view">
					
				</ul>
			</div>
		</div>
	</body>
	<script src="./js/mui.min.js"></script>
	<script type="text/javascript" src="js/config.js"></script>
	<script>
		mui.init({
			swipeBack:true //启用右滑关闭功能
		});
		mui.plusReady(function(){
			//检测本地是否存有数据
			var active_data = plus.storage.getItem('active_data');
			//设置dom操作类型 ：inner类初始插入以及appendchild
			var type = 'inner';
			if(active_data){
				//如果有值 则无需请求数据 直接载入本地数据
				var newAct = active_data.split(",");
				
				//执行dom 插入函数
				load(newAct,type);
			}else{
				//否则 请求ajax获取数据 插入    并把数据缓存到本地应用
				getData(type);
			}
		});
		
		
		
		//dom 插入函数
		var load = function(actData,type){
			var jpg = ipconfig().jpg;
			var list = document.getElementById('listParent');
			var html = [];
			mui.each(actData,function(index,item){
				html.push('<li class="mui-table-view-cell mui-media"><a href="#"><img src="'+jpg+item.thumb+'"/></a></li>');
			});
			//将dom动态写入
			//console.log(html);
			if(type == 'inner'){
				list.innerHTML = html.join("");
				//初始化scroll插件
				mui('.mui-scroll-wrapper').scroll({
					deceleration:5000
				});
			}else{
				list.appendChild(html.join(""));
				//初始化scroll插件
				mui('.mui-scroll-wrapper').scroll({
					deceleration:5000
				});
			}
			
		}
		
		
		//刷新触发ajax
		
		
		
		//ajax动态调用数据函数
		var getData = function(type){
			var type = type
			var ip = ipconfig().ip;
			mui.ajax(ip+'ActCart.getActivity',{
				dataType:'json',
				timeout:10000,
				type:'get',
				headers:{'Content-Type':'application/json'},
				success:function(data){ 
					//调用dom插入函数
					//console.log(data.data.data[0].id);
					load(data.data.data,type);
				},
				error:function(xhr,type,errorThrow){
					console.log(type);
				}
			});
		}
	</script>
</html>